/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package MeshlessShapeFunctions;

import Integration.IFunction1D;
import Integration.derivavty;

/**
 *
 * @author mark_o
 */
public class JQuarticSpline implements IKernelFunction, IFunction1D{

    public double evaluateNorm(double x, double y) {
        double xx = Math.abs(Math.sqrt(x*x+y*y));
        if(xx>1){ return 0.0;}
        else{
            if(xx>0.5){
                return 4.0/3.0*Math.pow((1-xx), 3);
            }else{
                return 2.0/3.0 + 4 * ( xx - 1 ) * xx * xx;
            }
        }
    }

    public double evaluateSque(double x, double y) {
        return evaluateNorm(x, 0)*evaluateNorm(0, y);
    }

    public double evaluatePrimeNormX(double x, double y) {
        double xx = Math.abs(Math.sqrt(x*x+y*y));
        if(xx>1){ return 0.0;}
        else{

            if(xx>0.5){
                return 4.0*Math.pow((1-xx), 2)*x/xx;
            }else{
                return 4 * ( 3*xx - 2 ) *x;
            }
        }
    }

    public double evaluatePrimeNormY(double x, double y) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public double evaluatePrimeSqueX(double x, double y) {
        return evaluatePrimeNormX(x, 0)*evaluatePrimeNormX(0, y);
    }

    public double evaluatePrimeSqueY(double x, double y) {
        return evaluatePrimeNormY(x, 0)*evaluatePrimeNormY(0, y);
    }

    public double evaluate(double x) {
        if(Math.abs(x)>1){ return 0.0;}
        else{
            x=Math.abs(x);
            return 1.0 - 6.0*x*x + 8.0*x*x*x - 3.0*x*x*x*x;
        }
    }

    public double evaluateDerivaty(double x) {
        if(Math.abs(x)>1){ return 0.0;}
        else{
            return -12.0*x + 24.0*x*x - 12.0*x*x*x;
        }
    }
    
    @Override
	public double evaluateSecondDerivaty(double d) {
		// TODO Auto-generated method stub
		return 0;
	}

    public static void main(String[] args){
        double a =-1.5,b=1.5,
        h=0.01;
        double x = a;

        JQuarticSpline f  = new JQuarticSpline();

        while(x<b+h){
            System.out.println(x+"\t"+derivavty.calculate(x, f));
            x+=h;
        }
    }

	@Override
	public double calculate(double x) {
		// TODO Auto-generated method stub
		return evaluate(x);
	}

	@Override
	public double calculateDerivaty(double x) {
		// TODO Auto-generated method stub
		return 0;
	}

	
}
